package com.zyz.I_多线程.常用方法;

/**
 * @author: vick
 * @Date: 2025/3/21
 * @Description:
 * @version: 1.0
 */
public class YieldThread implements Runnable{

    public static void main(String[] args) {
        YieldThread yieldThread = new YieldThread();
        Thread threadA = new Thread(yieldThread, "A");
        Thread threadB = new Thread(yieldThread, "B");
        threadA.start();

        threadB.start();
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {

            System.out.println(Thread.currentThread().getName() + "==>" + i);
            if (i == 3) {
                System.out.println("礼让");
                Thread.yield();
            }
        }
    }
}
